<?php
/**
 * Created by PhpStorm.
 * User: 王凯林
 * Date: 18/3/26
 * Time: 9:38
 */

namespace App\Http\Controllers\Admin;


use App\Common\Exceptions\AixinException;
use App\Common\Exceptions\AixinExceptionCode;
use App\Http\Controllers\Controller;
use App\Model\MoneyReport;
use Illuminate\Http\Request;

class MoneyReportController extends Controller
{

    /*
     * 报表首页
     */
    public function index(Request $request){
        $queryStr = $request->querystr;
//        $start
        //根据service中的文件找出来所有的记录->orderBy('create_time','desc')
//        dd(time());
        $datas = \App\Model\MoneyReport::where('shop_accounts.name', 'like', $queryStr.'%')
            ->orwhere('money_report.amount','like',$queryStr.'%')
            ->leftJoin('shop_accounts','money_report.uid','=','shop_accounts.uid')
            ->select('money_report.*','shop_accounts.name')
            ->orderBy('money_report.create_time','desc')
            ->with('providerName')
            ->paginate(10);
        return view('admin.moneyreport.index',['datas'=>$datas,'querystr'=>$queryStr]);
    }
    /*
     * 删除单条记录
     */
    public function destory(Request $request){
        if($request->has('id')){
            MoneyReport::where('id',$request->id)->delete();
        }else{
            throw new AixinException(AixinExceptionCode::MISSING_PARAM);
        }
    }
}